package cn.tedu.utils;/**
 * @Author 金帮嘉诚 @Date 2021-07-20 星期二 14:58
 */
/*本类用于测试*/

import cn.tedu.dao.CarDao;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * 知识点
 */
public class MybatisUtil {
    private static CarDao carDao = getSession().getMapper(CarDao.class);

    private static SqlSession getSession() {
        InputStream inputStream;

        try {
            inputStream = Resources.getResourceAsStream("application.yml");
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            SqlSession sqlSession = sqlSessionFactory.openSession();
            return sqlSession;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
    public static CarDao getCarDao(){
        return carDao;
    }

}
